﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using Newtonsoft.Json;
using ZHDJ.Data.Models.Center;
using ZHDJ.Data.Models.Common;
using ZHDJ.WebPage;
using ZHDJ.WebPage.Master;

namespace ZHDJ.Web.Portal.PartyRepresentative
{
    public partial class PartyRepresentativeInfoList : UseMorePageMasterPage
    {

        /// <summary>
        /// 工作室ID
        /// </summary>
        private string StudioID
        {
            get
            {
                return this.Request["StudioID"] ?? "null";
            }
        }
        /// <summary>
        /// 页数
        /// </summary>
        private string PageIndex
        {
            get
            {
                return this.Request["PageIndex"] ?? "";
            }
        }

        /// <summary>
        /// 每页条数
        /// </summary>
        private string PageSize
        {
            get
            {
                return this.Request["PageSize"] ?? "";
            }
        }
        private string DataCount
        {
            get
            {
                return this.Request["DataCount"] ?? "";
            }
        }
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                LoadData();
            }

            if (!string.IsNullOrEmpty(this.PageIndex))
            {
                this.WriteList();
            }
            else if (!string.IsNullOrEmpty(this.DataCount))
            {
                WriteDataCount();

            }
        }
        public void LoadData()
        {
            this.hdStudioID.Value = StudioID;
        }

        private void WriteList()
        {
            DataTable dt = PartyRepresentativeInfo.GetGridData(Convert.ToInt32(this.PageIndex), Convert.ToInt32(PageSize), "","", StudioID).Tables[0];

            dt.Columns.Add("ImgUrl", typeof(string));
            foreach (DataRow dr in dt.Rows)
            {
                dr["ImgUrl"] = UpFileBusiness.GetFileUrl(Convert.ToString(dr["ImageID"]));
            }
            var json = JsonConvert.SerializeObject(dt);
            Response.Clear();
            Response.Write(json);
            Response.End();
        }
        private void WriteDataCount()
        {
            Response.Clear();
            Response.Write(PartyRepresentativeInfo.GetGridData(0, 1, "", "", StudioID).Tables[1].Rows[0][0].ToString());
            Response.End();
        }
        /// <summary>
        /// 初始化module  如果通过url传参可不设置
        /// </summary>
        protected override void InitModule()
        {
            Category = "PartyRepresentativeInfo";
        }
    }
}